package com.example.projectone1;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

public class MainActivity extends Activity implements OnTouchListener {

	ImageView img;
	private int offset_x = 0;
	private int offset_y = 0;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        img = (ImageView) findViewById(R.id.image1);
        img.setOnTouchListener(this);
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    public boolean onTouch(View v, MotionEvent event) 
    {
    	System.out.println("switch");
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
            {
            	System.out.println("down");
                  // Here u can write code which is executed after the user touch on the screen 
                     break; 
            }
            case MotionEvent.ACTION_UP:
            {             
            	System.out.println("up");
                   // Here u can write code which is executed after the user release the touch on the screen    
                 break;
            }
            case MotionEvent.ACTION_MOVE:
            {  
            	System.out.println("move");
            	//Here u can write code which is executed when user move the finger on the screen   
            	int x = (int)event.getX();
				int y = (int)event.getY();
				
				RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                        new ViewGroup.MarginLayoutParams(
                        		RelativeLayout.LayoutParams.WRAP_CONTENT,
                        		RelativeLayout.LayoutParams.WRAP_CONTENT));
				lp.setMargins(x, y, 0, 0);
	         
				RelativeLayout relative1 = (RelativeLayout)findViewById(R.id.relative1);
				
				relative1.setLayoutParams(lp);
				
//				relative1.setMargins(left, top, right, bottom)
				
                break;
            }
        }
        return true;
    }
}